package com.example.project.controller;

import com.example.project.entity.Attendance;
import com.example.project.entity.Bussinesstrip;
import com.example.project.service.IBussinesstripService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "出差信息表")
@RestController
public class BussinesstripController {
    @Autowired
    private IBussinesstripService bussinesstripService;
    @CrossOrigin

    @ApiOperation(value = "对出差信息的添加")
    @GetMapping("getaddbussinesstrip")
    public int insert(Bussinesstrip bussinesstrip){
        System.out.println("进入增加出差信息方法");
        return bussinesstripService.add(bussinesstrip);
    }

    @ApiOperation(value = "查询所有出差信息方法")
    @GetMapping("/getallbussinesstrip")
    public List<Bussinesstrip> getAllBussinesstrip(Bussinesstrip bussinesstrip){
        System.out.println("进入查询所有出差信息的方法");
        List<Bussinesstrip> bussinesstripList=bussinesstripService.getAllBussinesstrip(bussinesstrip);
        return bussinesstripList;
    }

    @ApiOperation(value = "删除单条出差信息")
    @GetMapping("/deletebussinesstrip")
    public int deleteBussinesstrip(int id){
        System.out.println("进入出差信息删除方法");
        int returnValus=0;
        if(id!=0){
            Bussinesstrip bussinesstrip=new Bussinesstrip();
            bussinesstrip.setTripId(id);
            returnValus= bussinesstripService.deleteBussinesstrip(bussinesstrip);
        }
        return returnValus;
    }

    @ApiOperation(value = "对出差信息更新方法")
    @GetMapping("/updateBussinesstrip")
    public int updateBussinesstrip(Bussinesstrip bussinesstrip){
        System.out.println("进入出差信息更新方法");
        return bussinesstripService.updateBussinesstrip(bussinesstrip);
    }


    @ApiOperation(value = "获取单条出差数据")
    @GetMapping("/getoneBussinesstrip")
    public Bussinesstrip getBussinesstrip(int id){
        Bussinesstrip bussinesstrip=new Bussinesstrip();
        System.out.println("");
        if(id!=0){
            Bussinesstrip bussinesstrip1=new Bussinesstrip();
            bussinesstrip1.setTripId(id);
            bussinesstrip=bussinesstripService.getBussinesstrip(bussinesstrip1);
            System.out.println(""+bussinesstrip.getTripId());
        }
        return bussinesstrip;
    }
}
